]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
endSessionDialog: Warn when trying to install updates on battery power
authorKalev Lember <kalevlember@gmail.com>
Wed, 19 Feb 2014 18:59:47 +0000 (19:59 +0100)
committerKalev Lember <kalevlember@gmail.com>
Wed, 19 Feb 2014 23:27:35 +0000 (00:27 +0100)
Interrupting update installation can mess up the package database quite
a bit and could lead to totally destroying the distro installtion. To
avoid running out of juice during an upgrade, warn when someone tries to
install updates on battery power.

https://bugzilla.gnome.org/show_bug.cgi?id=722898

data/theme/gnome-shell.css
js/ui/endSessionDialog.js

index 35079d4216654fbe77ab6d0b6a8f83bb80a0f8fa..bb9ff5408a0c6e0eca13bcdd0b42bad1314bc17e 100644 (file)
@@ -1966,6 +1966,19 @@ StScrollBar StButton#vhandle:active {
     text-align: right;
 }
 
+.end-session-dialog-warning {
+    width: 28em;
+    color: #f57900;
+    padding-top: 6px;
+}
+
+.end-session-dialog-warning:rtl {
+    width: 28em;
+    color: #f57900;
+    padding-top: 6px;
+    text-align: right;
+}
+
 .end-session-dialog-logout-icon {
     border: 2px solid #8b8b8b;
     border-radius: 5px;
index 5f06fc14d9f7ab453cb06dd9434f618664e3b0c0..2ac185efb66f1cf1a6b568383c532f0ada3adb40 100644 (file)
@@ -75,6 +75,7 @@ const logoutDialogContent = {
                         "You will be logged out automatically in %d seconds.",
                         seconds).format(seconds);
     },
+    showBatteryWarning: false,
     confirmButtons: [{ signal: 'ConfirmedLogout',
                        label:  C_("button", "Log Out") }],
     iconStyleClass: 'end-session-dialog-logout-icon',
@@ -90,6 +91,7 @@ const shutdownDialogContent = {
                         seconds).format(seconds);
     },
     checkBoxText: C_("checkbox", "Install pending software updates"),
+    showBatteryWarning: true,
     confirmButtons: [{ signal: 'ConfirmedReboot',
                        label:  C_("button", "Restart") },
                      { signal: 'ConfirmedShutdown',
@@ -106,6 +108,7 @@ const restartDialogContent = {
                         "The system will restart automatically in %d seconds.",
                         seconds).format(seconds);
     },
+    showBatteryWarning: false,
     confirmButtons: [{ signal: 'ConfirmedReboot',
                        label:  C_("button", "Restart") }],
     iconName: 'view-refresh-symbolic',
@@ -121,6 +124,7 @@ const restartInstallDialogContent = {
                         "The system will automatically restart and install updates in %d seconds.",
                         seconds).format(seconds);
     },
+    showBatteryWarning: true,
     confirmButtons: [{ signal: 'ConfirmedReboot',
                        label:  C_("button", "Restart &amp; Install") }],
     iconName: 'view-refresh-symbolic',
@@ -149,6 +153,14 @@ const LogindSessionIface = '<node> \
 
 const LogindSession = Gio.DBusProxy.makeProxyWrapper(LogindSessionIface);
 
+const UPowerIface = '<node> \
+<interface name="org.freedesktop.UPower"> \
+    <property name="OnBattery" type="b" access="read"/> \
+</interface> \
+</node>';
+
+const UPowerProxy = Gio.DBusProxy.makeProxyWrapper(UPowerIface);
+
 function findAppFromInhibitor(inhibitor) {
     let desktopFile;
     try {
@@ -234,6 +246,19 @@ const EndSessionDialog = new Lang.Class({
         this._updatesFile = Gio.File.new_for_path('/system-update');
         this._preparedUpdateFile = Gio.File.new_for_path('/var/lib/PackageKit/prepared-update');
 
+        this._powerProxy = new UPowerProxy(Gio.DBus.system,
+                                           'org.freedesktop.UPower',
+                                           '/org/freedesktop/UPower',
+                                           Lang.bind(this, function(proxy, error) {
+                                               if (error) {
+                                                   log(error.message);
+                                                   return;
+                                               }
+                                               this._powerProxy.connect('g-properties-changed',
+                                                                        Lang.bind(this, this._sync));
+                                               this._sync();
+                                           }));
+
         this._secondsLeft = 0;
         this._totalSecondsToStayOpen = 0;
         this._applications = [];
@@ -284,6 +309,12 @@ const EndSessionDialog = new Lang.Class({
         this._checkBox.actor.connect('clicked', Lang.bind(this, this._sync));
         messageLayout.add(this._checkBox.actor);
 
+        this._batteryWarning = new St.Label({ style_class: 'end-session-dialog-warning',
+                                              text: _("Running on battery power: please plug in before installing updates.") });
+        this._batteryWarning.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
+        this._batteryWarning.clutter_text.line_wrap = true;
+        messageLayout.add(this._batteryWarning);
+
         this._scrollView = new St.ScrollView({ style_class: 'end-session-dialog-list' });
         this._scrollView.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
         this.contentLayout.add(this._scrollView,
@@ -337,6 +368,14 @@ const EndSessionDialog = new Lang.Class({
         if (dialogContent.subjectWithUpdates && this._checkBox.actor.checked)
             subject = dialogContent.subjectWithUpdates;
 
+        if (dialogContent.showBatteryWarning) {
+            // Warn when running on battery power
+            if (this._powerProxy.OnBattery && this._checkBox.actor.checked)
+                this._batteryWarning.opacity = 255;
+            else
+                this._batteryWarning.opacity = 0;
+        }
+
         let description;
         let displayTime = _roundSecondsToInterval(this._totalSecondsToStayOpen,
                                                   this._secondsLeft,
@@ -671,6 +710,12 @@ const EndSessionDialog = new Lang.Class({
         this._checkBox.actor.visible = (dialogContent.checkBoxText && preparedUpdate && updatesAllowed);
         this._checkBox.actor.checked = (preparedUpdate && updateAlreadyTriggered);
 
+        // We show the warning either together with the checkbox, or when
+        // updates have already been triggered, but the user doesn't have
+        // enough permissions to cancel them.
+        this._batteryWarning.visible = (dialogContent.showBatteryWarning &&
+                                        (this._checkBox.actor.visible || preparedUpdate && updateAlreadyTriggered && !updatesAllowed));
+
         this._updateButtons();
 
         if (!this.open(timestamp)) {